package com.atguigu.tingshu.album.job;

import cn.hutool.core.collection.CollectionUtil;
import com.atguigu.tingshu.album.mapper.AlbumInfoMapper;
import com.atguigu.tingshu.album.service.BloomFilterService;
import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.ognl.OgnlRuntime;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: atguigu
 * @create: 2024-05-21 09:21
 */
@Slf4j
@Component
public class BloomFilterResizeJob {


    @Autowired
    private BloomFilterService bloomFilterService;

    /**
     * 扩容定时任务：每月1号凌晨3点钟触发扩容
     */
    //@Scheduled(cron = "0/5 * * * * ?")
    @Scheduled(cron = "0 0 3 1 * ?")
    public void resizeBloomFilter() {
        RBloomFilter bloomFilter = bloomFilterService.resize();
        if (bloomFilter != null) {
            log.info("[布隆过滤器扩容]，扩容成功：元素个数：{}，容量：{}，误判率：{}，hash个数：{}", bloomFilter.count(), bloomFilter.getExpectedInsertions(), bloomFilter.getFalseProbability(), bloomFilter.getHashIterations());
        }
    }

}
